#说明：只会删除使用测试脚本打出的指定分支的apk包，(apk名字格式：flutter_$branch_$time.apk)
#使用：./delete_apk.sh  $branch

#http://appupload.yuemeng.ren/api/files/ls?path=/flutter/ 获取列表
#http://appupload.yuemeng.ren/api/files/rm?path=/flutter/flutter_featrue-mine-ui_09212033.apk 删除
#必备参数:
  # X-Requested-With
  # Cookie

# 需要删除的分支名
branch=$1
#branch='dev-yuyin'
#if [ -z "$1" ]; then
#  echo '请传入想要删除的分支名参数，eg: ./delete_apk.sh feature-fix-bug'
#  exit ;
#fi


function deleteApk() {
  if [[ $1 != *.apk ]]; then
    return;
    fi
  url='http://appupload.yuemeng.ren/api/files/rm?path=/flutter/'$1
  res=$(curl -sS ${url} -X GET -H 'X-Requested-With: XmlHttpRequest' -H 'Cookie: auth=gkndrXqidQ5BQKhEESuAbnk8KUG1WmBivs2jd35prY_NKhoCkg7URwhhhv8IeukWF4dCni890Y9yXDrpNirGk0G0w-IQeo8s0NIC-u9GDsKIAN8n2NpC8OYkX3MeRbyXziOYkVSTZsCLyyAQSu9LW1ElnOMFaTlZU6WM1cCybbNrWW6AgXuKJpgWelqyqff-Smk1wBQW1FtFWFe2Gbitri8f3etDV7kMF2Uu_BcH4Hi5qmhmmNbP3I1B4sT2n3MQVH_qEOhhlNZ-a4zmf-a2mdsMorkXfI4QSrB05Q7EMw==')
  echo $1' 删除成功!'
}

function  findApkList() {
    response=$(curl -sS 'http://appupload.yuemeng.ren/api/files/ls?path=/flutter/' -X GET -H 'X-Requested-With: XmlHttpRequest' -H 'Cookie: auth=gkndrXqidQ5BQKhEESuAbnk8KUG1WmBivs2jd35prY_NKhoCkg7URwhhhv8IeukWF4dCni890Y9yXDrpNirGk0G0w-IQeo8s0NIC-u9GDsKIAN8n2NpC8OYkX3MeRbyXziOYkVSTZsCLyyAQSu9LW1ElnOMFaTlZU6WM1cCybbNrWW6AgXuKJpgWelqyqff-Smk1wBQW1FtFWFe2Gbitri8f3etDV7kMF2Uu_BcH4Hi5qmhmmNbP3I1B4sT2n3MQVH_qEOhhlNZ-a4zmf-a2mdsMorkXfI4QSrB05Q7EMw==')
    #echo $response
    list=$(echo ${response} | jq -r '.results[]')
    #echo $list
    names=$(echo ${response} | jq '.results[].name')
    name_list_tem=(${names//" "/})
    name_list=();
    for var in ${name_list_tem[@]} ;
    do
        tem=(${var//\"/})
        if [[ $tem == flutter_$branch* ]];then
            name_list[${#name_list[@]}]=$tem
          fi
    done

    if [ ${#name_list[@]} == 0 ]; then
        echo '未找到该分支名的apk：flutter_'$branch
    fi

     for (( i = 0; i < ${#name_list[@]}; i++ )); do
        deleteApk ${name_list[i]}
    #    echo ${name_list[i]};
        done
}

#echo '哈哈哈哈哈'
pwd
cd ./lib
pwd
echo $1
echo `find $1`